import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import numpy as np

path="../result"
list1=["线性","抛物线","样条插值"]




for item in list1:
    # 读取指定列索引字段的数据
    # csv_data = pd.read_csv("../result/Si-"+item+"-结果.csv",usecols=['wavelength', 'n'])
    csv_data = pd.read_csv("../result/siO2-"+item+"-结果.csv",usecols=['wavelength', 'n'])
    lambdas=csv_data["wavelength"]
    x=[1/(cell*cell) for cell in lambdas]
    y=csv_data["n"]
    
    a=np.polyfit(x,y,2)   #用2次多项式拟合x,y数组
    b=np.poly1d(a)        #拟合完成后生成多项式对象
    c=b(x)                #获取x在多项式处的值
    
    print("a=",a)
    print("b=\n",b)
    # print("c=",c)
    plt.scatter(lambdas,y,marker='o',label='original datas')                  #对原始数据做散点图
    plt.plot(lambdas,c,ls='--',c='red',label='fitting with 4 polynomial')#对拟合之后的数据作图
    plt.legend()                                                        #给图加上图例
    plt.show()




